
package com.rt.schedulenew.utils.util;

import com.rt.schedulenew.utils.base.CommonUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.sql.Time;
import java.text.DateFormat;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;

public class DateUtil {
    private static Logger logger = LoggerFactory.getLogger(DateUtil.class);

    public static final String FORMAT_DATETIME = "yyyy-MM-dd HH:mm:ss";
    public static final String FORMAT_DATE = "yyyy-MM-dd";
    public static final String FORMAT_TIME = "HH:mm:ss";

    public static final String FORMAT_HHMM = "HH:mm";

    public static final String FORMAT_DATETIME_MM = "yyyy-MM-dd HH:mm";


    public static final String FORMAT_DATE_YYYYMMDD = "yyyyMMdd";


    public static final String FORMAT_DATE_ZH = "yyyy年MM月dd日";

    public static final String FORMAT_DATETIME_ZH = "yyyy年MM月dd日 HH时mm分ss秒";

    public static final String TYPE_DATE = "date";

    public static final String TYPE_DATETIME = "datetime";


    public static int DATE_ORDER_ASC = 0;
    public static int DATE_ORDER_DESC = 1;

    public static Date formatDate(Date date, String pattern) {
        if (date == null || null == pattern || pattern.isEmpty()) {
            return null;
        }
        SimpleDateFormat format = new SimpleDateFormat(pattern);
        Date result = null;
        try {
            result = format.parse(format.format(date));
        } catch (ParseException e) {
            logger.error(e.getMessage(), e);
        }
        return result;
    }

    public static Date parse(String date, String pattern) {
        if (date == null || date.isEmpty() || null == pattern || pattern.isEmpty()) {
            return null;
        }
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(pattern);
            return sdf.parse(date);
        } catch (ParseException e) {
            logger.error(e.getMessage(), e);
            return null;
        }
    }

    public static String getCurrDateStr() {
        return DateToStringYYMMDD(new Date());
    }

    /**
     * 获取当前日期
     *
     * @return
     */
    public static Date getCurrDate() {
        return parse(DateToStringYYMMDD(new Date()), FORMAT_DATE);
    }

    public static Date getNow() {
        return new Date(System.currentTimeMillis());
    }

    public static String DateToStringYYMMDD(Date date) {
        if (date == null || "".equals(date)) {
            return null;
        }
        SimpleDateFormat format = new SimpleDateFormat(FORMAT_DATE);
        String result = format.format(date);
        return result;
    }

    public static String getDateYYMMDD(Date date) {
        if (date == null || "".equals(date)) {
            return null;
        }
        SimpleDateFormat format = new SimpleDateFormat(FORMAT_DATE_YYYYMMDD);
        String result = format.format(date);
        return result;
    }

    public static String getNowDateYYMMDD() {
        return getDateYYMMDD(new Date());
    }

    public static String getDateTime() {
        return date2Str(new Date());
    }

    public static String date2Str(Date date) {
        if (date == null || date.equals("")) {
            return null;
        }
        SimpleDateFormat format = new SimpleDateFormat(FORMAT_DATETIME);
        String result = null;
        result = format.format(date);
        return result;
    }

    public static String DateToStringHHMMSS(Date date) {
        if (date == null || date.equals("")) {
            return null;
        }
        SimpleDateFormat format = new SimpleDateFormat(FORMAT_TIME);
        String result = null;
        result = format.format(date);
        return result;
    }

    /**
     * 日期格式化
     *
     * @param date
     * @param pattern
     * @return
     */
    public static String date2Str(Date date, String pattern) {
        if (date == null || date.equals("")) {
            return null;
        }
        SimpleDateFormat format = new SimpleDateFormat(pattern);
        String result = format.format(date);
        return result;
    }

    public static Date stringToDateYYMMDD(String date) {
        if (date == null || date.equals("")) {
            return null;
        }
        SimpleDateFormat format = new SimpleDateFormat(FORMAT_DATE);
        Date result = null;
        try {
            result = format.parse(date);
        } catch (ParseException e) {
            logger.error(e.getMessage(), e);
        }
        return result;
    }

    public static Date stringToDateYYMMDDHHMMSS(String date) {
        return parse(date, FORMAT_DATETIME);
    }

    public static Date dayBeginTime(Date date) {
        String dateStr = formatDateSplit(date, "-");
        dateStr += " 00:00:00";
        return getDate(dateStr, TYPE_DATETIME);
    }

    public static Date dayEndTime(Date date) throws ParseException {
        String dateStr = formatDateSplit(date, "-");
        dateStr += " 23:59:59";
        return getDate(dateStr, TYPE_DATETIME);
    }

    public static Date getDate(String dateValue, String dateType) {
        if (dateValue == null) {
            return null;
        }
        try {
            if (TYPE_DATE.equals(dateType)) {
                SimpleDateFormat sfdate = new SimpleDateFormat(FORMAT_DATE);
                return sfdate.parse(dateValue);
            }
            if (TYPE_DATETIME.equals(dateType)) {
                SimpleDateFormat sftime = new SimpleDateFormat(FORMAT_DATETIME);
                return sftime.parse(dateValue);
            }
        } catch (ParseException e) {
            logger.error(e.getMessage(), e);
        }
        return null;
    }

    public static java.sql.Date getSqlDate(String dateValue, String dateType) throws ParseException {
        Date date = getDate(dateValue, dateType);
        if (date == null) {
            return null;
        }
        return new java.sql.Date(date.getTime());
    }

    public static Date yearAdd(String date, int to) {
        Date d = null;
        try {
            d = java.sql.Date.valueOf(date);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            d = new Date();
        }
        Calendar strDate = Calendar.getInstance();
        strDate.setTime(d);
        strDate.add(Calendar.YEAR, to);
        return strDate.getTime();
    }

    public static Date mouthAdd(String date, int to) {
        Date d = null;
        try {
            d = java.sql.Date.valueOf(date);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            d = new Date();
        }
        Calendar strDate = Calendar.getInstance();
        strDate.setTime(d);
        strDate.add(Calendar.MONTH, to);
        return strDate.getTime();
    }

    public static Date dateAdd(String date, int to) {
        Date d = null;
        try {
            d = java.sql.Date.valueOf(date);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            d = new Date();
        }
        Calendar strDate = Calendar.getInstance();
        strDate.setTime(d);
        strDate.add(Calendar.DATE, to);
        return strDate.getTime();
    }

    public static Date hourAdd(String date, int to) {
        Date d = null;
        try {
            d = java.sql.Date.valueOf(date);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            d = new Date();
        }
        Calendar strDate = Calendar.getInstance();
        strDate.setTime(d);
        strDate.add(Calendar.HOUR, to);
        return strDate.getTime();
    }

    public static Date minAdd(String date, int to) {
        Date d = null;
        try {
            d = parse(date, FORMAT_DATETIME_MM);
            if (Objects.isNull(d)) {
                d = new Date();
            }
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            d = new Date();
        }
        Calendar strDate = Calendar.getInstance();
        strDate.setTime(d);
        strDate.add(Calendar.MINUTE, to);
        return strDate.getTime();
    }

    public static String addMinute1(int minute) {
        SimpleDateFormat sdf = new SimpleDateFormat(FORMAT_HHMM);
        Calendar nowTime = Calendar.getInstance();
        nowTime.add(Calendar.MINUTE, minute);
        return sdf.format(nowTime.getTime());
    }

    public static Date secAdd(String date, int to) {
        Date d = null;
        try {
            d = java.sql.Date.valueOf(date);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            d = new Date();
        }
        Calendar strDate = Calendar.getInstance();
        strDate.setTime(d);
        strDate.add(Calendar.SECOND, to);
        return strDate.getTime();
    }

    public static String dateToStamp(String s) throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(FORMAT_DATETIME);
        Date date = simpleDateFormat.parse(s);
        long ts = date.getTime();
        String res = String.valueOf(ts);
        return res;
    }

    public static java.sql.Date dateAdd(java.sql.Date date, int to) {
        Calendar strDate = Calendar.getInstance();
        strDate.setTime(date);
        strDate.add(Calendar.DATE, to);
        return new java.sql.Date(strDate.getTime().getTime());
    }

    public static java.sql.Date dateAdd(Date date, int to) {
        Calendar strDate = Calendar.getInstance();
        strDate.setTime(date);
        strDate.add(Calendar.DATE, to);
        return new java.sql.Date(strDate.getTime().getTime());
    }

    public static java.sql.Date dateAdd(int to) {
        return dateAdd(new Date(), to);
    }

    public static String addDays(int m) {
        Calendar c = Calendar.getInstance();
        c.setTime(new Date());
        c.add(Calendar.DATE, m);
        return new SimpleDateFormat(FORMAT_DATE).format(c.getTime());
    }

    public static int diffMin(Date date, Date date2) {
        return (int) ((getMillis(date) - getMillis(date2)) / 60000L);
    }


    public static Date addSecond(Date date, int second) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.SECOND, second);
        return new Date(cal.getTime().getTime());
    }

    public static String addSecond(String time, int second) {
        SimpleDateFormat format = new SimpleDateFormat(FORMAT_TIME);
        Date date = null;
        try {
            date = format.parse(time);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.SECOND, second);
        return format.format(cal.getTime());
    }

    public static long getMillis(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c.getTimeInMillis();
    }


    public static String addDays2(String date, int m) {
        Date d = null;
        Calendar c = Calendar.getInstance();
        try {
            d = new SimpleDateFormat("yy-MM-dd").parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        c.setTime(d);
        c.add(Calendar.DATE, m);
        return new SimpleDateFormat(FORMAT_DATE).format(c.getTime());
    }


    public static String addMinutes(String date, int m) {
        Date d = null;
        Calendar c = Calendar.getInstance();
        try {
            d = new SimpleDateFormat(FORMAT_DATETIME).parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        c.setTime(d);
        c.add(Calendar.MINUTE, m);
        return new SimpleDateFormat(FORMAT_DATETIME).format(c.getTime());
    }

    public static String addMinutes1(String date, int m) {
        Date d = null;
        Calendar c = Calendar.getInstance();
        try {
            d = new SimpleDateFormat(FORMAT_DATETIME_MM).parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        c.setTime(d);
        c.add(12, m);
        return new SimpleDateFormat(FORMAT_DATETIME_MM).format(c.getTime());
    }

    public static String addMinutes2(String date, int m) {
        try {
            Calendar c = Calendar.getInstance();
            c.setTime(new SimpleDateFormat(FORMAT_HHMM).parse(date));
            c.add(Calendar.MINUTE, m);
            return new SimpleDateFormat(FORMAT_HHMM).format(c.getTime());
        } catch (ParseException e) {
            e.printStackTrace();
            return "";
        }
    }

    public static String getMaxDayOfThisMonth(int year, int month) {
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.YEAR, year);
        cal.set(Calendar.MONTH, month - 1);
        int lastDay = cal.getActualMaximum(Calendar.DATE);
        cal.set(Calendar.DATE, lastDay);
        SimpleDateFormat sdf = new SimpleDateFormat(FORMAT_DATE);
        return sdf.format(cal.getTime());
    }


    public static String formatDateSplit(Date date, String splitChar) {
        SimpleDateFormat sfdate = new SimpleDateFormat("yyyy" + splitChar + "MM" + splitChar + "dd");
        return sfdate.format(date);
    }

    public static String format(Object dateValue, String dateType) {
        if (dateValue == null) {
            return "";
        }
        if (dateValue instanceof java.sql.Date) {
            return dateValue.toString();
        }
        if (!(dateValue instanceof Date)) {
            return "非日期类型";
        }
        if (TYPE_DATE.equals(dateType)) {
            SimpleDateFormat sfdate = new SimpleDateFormat(FORMAT_DATE);
            return sfdate.format(dateValue);
        }
        if (TYPE_DATETIME.equals(dateType)) {
            SimpleDateFormat sftime = new SimpleDateFormat(FORMAT_DATETIME);
            return sftime.format(dateValue);
        }
        return "非法日期格式[" + dateType + "]";
    }

    public static String formatZh(Date dateValue, String dateType) {
        if (dateValue == null) {
            return "";
        }
        if (dateValue instanceof java.sql.Date) {
            return dateValue.toString();
        }
        if (!(dateValue instanceof Date)) {
            return "非日期类型";
        }
        if (TYPE_DATE.equals(dateType)) {
            SimpleDateFormat sfdate = new SimpleDateFormat(FORMAT_DATE_ZH);
            return sfdate.format(dateValue);
        }
        if (TYPE_DATETIME.equals(dateType)) {
            SimpleDateFormat sftime = new SimpleDateFormat(FORMAT_DATETIME_ZH);
            return sftime.format(dateValue);
        }
        return "非法日期格式[" + dateType + "]";
    }

    public static String chDateChange(String sDate, String DelimeterChar) {
        String[] tmpArr = sDate.split(DelimeterChar);
        tmpArr[0] += "年";
        tmpArr[1] += "月";
        tmpArr[2] += "日";
        return tmpArr[0] + tmpArr[1] + tmpArr[2];
    }

    public static String getSysdate() {
        Timestamp timeNow = new Timestamp(System.currentTimeMillis());
        return timeNow.toString().substring(0, 10);
    }

    public static String getSysdate(String formatType) {
        Timestamp timeNow = new Timestamp(System.currentTimeMillis());
        return formatZh(timeNow, formatType);
    }

    public static int getWeekDay(String strDay) {
        Date day = dateAdd(strDay, -1);
        Calendar strDate = Calendar.getInstance();
        strDate.setTime(day);
        int meStrDate = strDate.get(7);
        return meStrDate;
    }

    public static int getWeekDay(Date date) {
        Date day = dateAdd(format(date, TYPE_DATE), -1);
        Calendar strDate = Calendar.getInstance();
        strDate.setTime(day);
        int meStrDate = strDate.get(7);
        return meStrDate;
    }

    public static String getMonday(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat(FORMAT_DATE);
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        int dayWeek = cal.get(Calendar.DAY_OF_WEEK);
        if (1 == dayWeek) {
            cal.add(Calendar.DATE, -1);
        }
        cal.setFirstDayOfWeek(2);
        int day = cal.get(7);
        cal.add(5, cal.getFirstDayOfWeek() - day);
        String imptimeBegin = sdf.format(cal.getTime());
        return imptimeBegin;
    }

    private static boolean isLegalDate(String sDate) {
        int legalLen = 10;
        if (sDate == null || sDate.length() != legalLen) {
            return false;
        }
        DateFormat formatter = new SimpleDateFormat(FORMAT_DATE);
        try {
            Date date = formatter.parse(sDate);
            return sDate.equals(formatter.format(date));
        } catch (Exception e) {
            return false;
        }
    }

    public static String getDayOfWeek(Date date) {
        String[] dayNames = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK) - 1;
        if (dayOfWeek < 0) {
            dayOfWeek = 0;
        }
        return dayNames[dayOfWeek];
    }

    public static String getDayOfWeekDate(Date date) {
        String[] dayNames = {"0", "1", "2", "3", "4", "5", "6"};
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK) - 1;
        if (dayOfWeek < 0) {
            dayOfWeek = 0;
        }
        return dayNames[dayOfWeek];
    }

    public static int getBetweenDays(String t1, String t2) throws ParseException {
        DateFormat format = new SimpleDateFormat(FORMAT_DATE);
        int betweenDays = 0;
        Date d1 = format.parse(t1);
        Date d2 = format.parse(t2);
        betweenDays = getBetweenDays(d1, d2);
        return betweenDays;
    }

    public static int getBetweenDays(String t1, String t2, boolean swapDate) throws ParseException {
        DateFormat format = new SimpleDateFormat(FORMAT_DATE);
        int betweenDays = 0;
        Date d1 = format.parse(t1);
        Date d2 = format.parse(t2);
        betweenDays = getBetweenDays(d1, d2, swapDate);
        return betweenDays;
    }

    public static int getBetweenDays(Date d1, Date d2, boolean swapDate) {
        if (d1 == null || d2 == null) {
            return -1;
        }
        Calendar c1 = Calendar.getInstance();
        Calendar c2 = Calendar.getInstance();
        c1.setTime(d1);
        c2.setTime(d2);
        if (swapDate && c1.after(c2)) {
            c2.setTime(d1);
            c1.setTime(d2);
        }
        int betweenYears = c2.get(Calendar.YEAR) - c1.get(Calendar.YEAR);
        int betweenDays = c2.get(Calendar.DAY_OF_YEAR) - c1.get(Calendar.DAY_OF_YEAR);
        for (int i = 0; i < betweenYears; ++i) {
            c1.set(Calendar.YEAR, c1.get(Calendar.YEAR) + 1);
            betweenDays += c1.getMaximum(Calendar.DAY_OF_YEAR);
        }
        return betweenDays;
    }

    public static int getBetweenDays(Date d1, Date d2) {
        if (d1 == null || d2 == null) {
            return -1;
        }
        Calendar c1 = Calendar.getInstance();
        Calendar c2 = Calendar.getInstance();
        c1.setTime(d1);
        c2.setTime(d2);
        if (c1.after(c2)) {
            c2.setTime(d1);
            c1.setTime(d2);
        }
        int betweenYears = c2.get(Calendar.YEAR) - c1.get(Calendar.YEAR);
        int betweenDays = c2.get(Calendar.DAY_OF_YEAR) - c1.get(Calendar.DAY_OF_YEAR);
        for (int i = 0; i < betweenYears; ++i) {
            c1.set(Calendar.YEAR, c1.get(Calendar.YEAR) + 1);
            betweenDays += c1.getMaximum(Calendar.DAY_OF_YEAR);
        }
        return betweenDays;
    }

    public static boolean betweenDays(java.sql.Date fromDate, java.sql.Date toDate, java.sql.Date testDate) {
        if (fromDate == null || toDate == null || testDate == null) {
            return false;
        }
        if (fromDate.getTime() > toDate.getTime()) {
            java.sql.Date tempDate = fromDate;
            fromDate = toDate;
            toDate = tempDate;
        }
        long testDateTime = testDate.getTime();
        return (testDateTime <= fromDate.getTime() || testDateTime <= toDate.getTime()) && (testDateTime >= fromDate.getTime() || testDateTime >= toDate.getTime());
    }

    public static String getLastDateDayOfMonth(int year, int month) {
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.YEAR, year);
        cal.set(Calendar.MONTH, month);
        int lastDate = cal.getActualMaximum(Calendar.DATE);
        return year + "-" + (month + 1) + "-" + lastDate;
    }

    public static String getSpecifiedDayAfter(String specifiedDay) {
        Calendar c = Calendar.getInstance();
        Date date = null;
        try {
            date = new SimpleDateFormat(FORMAT_DATE).parse(specifiedDay);
        } catch (ParseException e) {
            logger.error(e.getMessage(), e);
        }
        c.setTime(date);
        int day = c.get(Calendar.DATE);
        c.set(Calendar.DATE, day + 1);
        String dayAfter = new SimpleDateFormat(FORMAT_DATE).format(c.getTime());
        return dayAfter;
    }

    public static boolean isSameDate(Date d1, Date d2) {
        boolean result = false;
        Calendar c1 = Calendar.getInstance();
        c1.setTime(d1);
        Calendar c2 = Calendar.getInstance();
        c2.setTime(d2);
        if (c1.get(Calendar.YEAR) == c2.get(Calendar.YEAR)
                && c1.get(Calendar.MONTH) == c2.get(Calendar.MONTH)
                && c1.get(Calendar.DATE) == c2.get(Calendar.DATE)) {
            result = true;
        }
        return result;
    }

    public static Time getSystemTime() {
        Calendar c1 = Calendar.getInstance();
        int hour = c1.get(Calendar.HOUR_OF_DAY);
        int minute = c1.get(Calendar.MINUTE);
        int second = c1.get(Calendar.SECOND);
        Time systemTime = Time.valueOf(hour + ":" + minute + ":" + second);
        return systemTime;
    }

    public static boolean isWeekend(String strDate) {
        int weekDay = getWeekDay(strDate);
        return weekDay == 6 || weekDay == 7;
    }

    public static boolean isWeekend(Date date) {
        int weekDay = getWeekDay(format(date, TYPE_DATE));
        return weekDay == 6 || weekDay == 7;
    }

    public static boolean isHoliday(String strDate) {
        return false;
    }

    public static List<java.sql.Date> getBetweenDates(java.sql.Date fromDate, java.sql.Date toDate) {
        List<java.sql.Date> result = new ArrayList<java.sql.Date>();
        if (toDate.getTime() < fromDate.getTime()) {
            java.sql.Date tempDate = fromDate;
            fromDate = toDate;
            toDate = tempDate;
        }
        for (Calendar ca = Calendar.getInstance(); fromDate.getTime() <= toDate.getTime(); fromDate = new java.sql.Date(ca.getTime().getTime())) {
            ca.setTime(fromDate);
            java.sql.Date tempDate2 = new java.sql.Date(ca.getTime().getTime());
            result.add(tempDate2);
            ca.add(Calendar.DATE, 1);
        }
        return result;
    }

    public static List<java.sql.Date> getAllDate(List<java.sql.Date[]> dateList) {
        List<java.sql.Date> result = new ArrayList<java.sql.Date>();
        for (Object[] objs : dateList) {
            if (objs[0] != null) {
                if (objs[1] == null) {
                    continue;
                }
                java.sql.Date date1 = (java.sql.Date) objs[0];
                java.sql.Date date2 = (java.sql.Date) objs[1];
                List<java.sql.Date> betweenDates = getBetweenDates(date1, date2);
                for (java.sql.Date date3 : betweenDates) {
                    if (!result.contains(date3)) {
                        result.add(date3);
                    }
                }
            }
        }
        return result;
    }

    public static int getAge(Date birthdayDate) {
        String formatCurrent = new SimpleDateFormat(FORMAT_DATE).format(new Date());
        int firstCu = formatCurrent.indexOf("-");
        int lastCu = formatCurrent.lastIndexOf("-");
        String currentYearStr = formatCurrent.substring(0, firstCu);
        String currentMonthStr = formatCurrent.substring(firstCu + 1, lastCu);
        String currentDayStr = formatCurrent.substring(lastCu + 1);
        int currentYear = Integer.parseInt(currentYearStr);
        int currentMonth = Integer.parseInt(currentMonthStr);
        int currentDay = Integer.parseInt(currentDayStr);
        String formatBirthday = new SimpleDateFormat(FORMAT_DATE).format(birthdayDate);
        int first = formatBirthday.indexOf("-");
        int last = formatBirthday.lastIndexOf("-");
        String birthYearStr = formatBirthday.substring(0, first);
        String birthMonthStr = formatBirthday.substring(first + 1, last);
        String birthDayStr = formatBirthday.substring(last + 1);
        int birthYear = Integer.parseInt(birthYearStr);
        int birthMonth = Integer.parseInt(birthMonthStr);
        int birthDay = Integer.parseInt(birthDayStr);
        if (currentMonth > birthMonth) {
            return currentYear - birthYear;
        }
        if (currentMonth != birthMonth) {
            return currentYear - birthYear - 1;
        }
        if (currentDay >= birthDay) {
            return currentYear - birthYear;
        }
        return currentYear - birthYear - 1;
    }

    public static String getAges(Date birthdayDate) {
        if (birthdayDate == null) {
            return null;
        }
        Calendar cal = Calendar.getInstance();
        int yearNow = cal.get(Calendar.YEAR);
        int monthNow = cal.get(Calendar.MONTH) + 1;
        int preMonth = cal.get(Calendar.MONTH);
        int dayOfMonthNow = cal.get(Calendar.DATE);
        Date date2 = cal.getTime();
        cal.setTime(birthdayDate);
        int yearBirth = cal.get(Calendar.YEAR);
        int monthBirth = cal.get(Calendar.MONTH) + 1;
        int dayOfMonthBirth = cal.get(Calendar.DATE);
        Date date3 = cal.getTime();
        int age = yearNow - yearBirth;
        int month = monthNow - monthBirth;
        int day = dayOfMonthNow - dayOfMonthBirth;
        String s = "";
        if (day < 0) {
            Date dates;
            if (--month == 0) {
                dates = date3;
            } else {
                dates = stringToDateYYMMDD(yearBirth + "-" + preMonth + "-" + dayOfMonthBirth);
            }
            day = (int) ((date2.getTime() - dates.getTime()) / 86400000L);
        }
        if (month < 0) {
            --age;
            ++month;
        }
        if (age > 0) {
            s = s + age + "岁";
        }
        if (month > 0 && age < 6) {
            s = s + month + "月";
        }
        if (day > 0 && age == 0) {
            s = s + day + "天";
        }
        if (day == 0 && age == 0 && month == 0) {
            s = "1天";
        }
        return s;
    }

    public static String getYearMonth(Date dateObj) {
        if (dateObj == null) {
            return "";
        }
        Calendar ca = Calendar.getInstance();
        ca.setTime(dateObj);
        int month = ca.get(Calendar.MONTH) + 1;
        String strMonth = (month < 10) ? ("0" + month) : String.valueOf(month);
        String yearMonth = ca.get(Calendar.YEAR) + strMonth;
        return yearMonth;
    }

    public static String getPreYearMonth(String yearMonth) {
        if (yearMonth.length() == 6) {
            int year = Integer.parseInt(yearMonth.substring(0, 4));
            int month = Integer.parseInt(yearMonth.substring(4));
            if (month != 1) {
                --month;
            } else {
                --year;
                month = 12;
            }
            return year + ((month < 10) ? ("0" + month) : String.valueOf(month));
        }
        return "";
    }

    public static int getYearFromDate(String specifiedDay) throws ParseException {
        Calendar ca = Calendar.getInstance();
        ca.setTime(new SimpleDateFormat(FORMAT_DATE).parse(specifiedDay));
        return ca.get(Calendar.YEAR);
    }

    public static Integer getCurrentYear() {
        Calendar ca = Calendar.getInstance();
        return ca.get(Calendar.YEAR);
    }

    public static Integer getCurrentMonth() {
        Calendar ca = Calendar.getInstance();
        return ca.get(Calendar.MONTH) + 1;
    }

    public static String getCurrentDate() {
        return new SimpleDateFormat(FORMAT_DATE).format(System.currentTimeMillis());
    }

    public static String getCurrentTime() {
        return new SimpleDateFormat(FORMAT_TIME).format(System.currentTimeMillis());
    }

    public static String getCurrentDateTime() {
        return new SimpleDateFormat(FORMAT_DATETIME).format(System.currentTimeMillis());
    }

    public static String formatTime(Long ms) {
        int ss = 1000;
        int mi = ss * 60;
        Integer hh = mi * 60;
        Integer dd = hh * 24;
        Long hour = ms / hh;
        long minute = (ms - hour * hh) / mi;
        long second = (ms - hour * hh - minute * mi) / ss;
        StringBuilder sb;
        sb = new StringBuilder();
        if (hour > 0L) {
            sb.append(hour + "小时");
        }
        if (minute > 0L) {
            sb.append(minute + "分");
        }
        if (second > 0L) {
            sb.append(second + "秒");
        }
        return sb.toString();
    }

    public static String next(String dateStr, int offset) {
        Calendar c = Calendar.getInstance();
        Date date = null;
        try {
            SimpleDateFormat dateFormat = new SimpleDateFormat(FORMAT_DATETIME);
            date = dateFormat.parse(dateStr);
            c.setTime(date);
            int day = c.get(Calendar.DATE);
            c.set(Calendar.DATE, day + offset);
            return dateFormat.format(c.getTime());
        } catch (ParseException e) {
            logger.error(e.getMessage(), e);
        }
        return null;
    }

    public static long[] getDistanceTimes(String str1, String str2) {
        DateFormat df = new SimpleDateFormat(FORMAT_DATETIME);
        long day = 0L;
        long hour = 0L;
        long min = 0L;
        long sec = 0L;
        try {
            Date one = df.parse(str1);
            Date two = df.parse(str2);
            long time1 = one.getTime();
            long time2 = two.getTime();
            long diff;
            if (time1 < time2) {
                diff = time2 - time1;
            } else {
                diff = time1 - time2;
            }
            day = diff / 86400000L;
            hour = diff / 3600000L - day * 24L;
            min = diff / 60000L - day * 24L * 60L - hour * 60L;
            sec = diff / 1000L - day * 24L * 60L * 60L - hour * 60L * 60L - min * 60L;
        } catch (ParseException e) {
            logger.error(e.getMessage(), e);
        }
        return new long[]{day, hour, min, sec};
    }

    public static Date getDateInterval(String strDate, int calendarField, int amount) throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(FORMAT_DATETIME);
        Date date = simpleDateFormat.parse(strDate);
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.add(calendarField, amount);
        return c.getTime();
    }

    public static long getTimeMillisecond() {
        Date currentDate = new Date();
        return currentDate.getTime();
    }

    public static String timestampToDateStr(Long timestamp, String formatDate) {
        String format = "";
        try {
            Date date = new Date(timestamp);
            DateFormat dateFormat = new SimpleDateFormat(formatDate);
            format = dateFormat.format(date);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return format;
    }

    public static Boolean compareTime(String timeStr0, String timeStr1) {
        DateFormat df = new SimpleDateFormat("HH:mm");
        try {
            Date dt0 = df.parse(timeStr0);
            Date dt2 = df.parse(timeStr1);
            return !dt0.after(dt2);
        } catch (ParseException e) {
            logger.error(e.getMessage(), e);
            return false;
        }
    }

    public static int compareDate(String DATE1, String DATE2) {
        DateFormat df = new SimpleDateFormat(FORMAT_DATETIME);
        try {
            Date dt1 = df.parse(DATE1);
            Date dt2 = df.parse(DATE2);
            if (dt1.getTime() > dt2.getTime()) {
                return 1;
            }
            if (dt1.getTime() < dt2.getTime()) {
                return -1;
            }
            return 0;
        } catch (Exception exception) {
            exception.printStackTrace();
            return -2;
        }
    }

    public static boolean compare(String time1, String time2) {
        SimpleDateFormat sdf = new SimpleDateFormat(FORMAT_DATE);
        try {
            Date a = sdf.parse(time1);
            Date b = sdf.parse(time2);
            return a.before(b);
        } catch (ParseException e) {
            logger.error(e.getMessage(), e);
            return false;
        }
    }

    public static String getSexCode(String certificateNo) {
        int idxSexStart = 16;
        int birthYearSpan = 4;
        if (certificateNo.length() == 15) {
            idxSexStart = 14;
            birthYearSpan = 2;
        }
        String idxSexStr = certificateNo.substring(idxSexStart, idxSexStart + 1);
        int idxSex = Integer.parseInt(idxSexStr) % 2;
        String sex = (idxSex == 1) ? "0" : "1";
        return sex;
    }

    public static String getBirthDate(String certificateNo) {
        int idxSexStart = 16;
        int birthYearSpan = 4;
        if (certificateNo.length() == 15) {
            idxSexStart = 14;
            birthYearSpan = 2;
        }
        String year = ((birthYearSpan == 2) ? "19" : "") + certificateNo.substring(6, 6 + birthYearSpan);
        String month = certificateNo.substring(6 + birthYearSpan, 6 + birthYearSpan + 2);
        String day = certificateNo.substring(8 + birthYearSpan, 8 + birthYearSpan + 2);
        String birthday = year + '-' + month + '-' + day;
        return birthday;
    }


    public static Map<String, Object> getAfterTime(int hour_) {
        long currentTime = System.currentTimeMillis();
        currentTime += hour_ * 60 * 60 * 1000;
        Date date = new Date(currentTime);
        SimpleDateFormat dateFormat = new SimpleDateFormat(FORMAT_DATE);
        SimpleDateFormat timeFormat = new SimpleDateFormat(FORMAT_TIME);
        Map<String, Object> map = new HashMap<>();
        map.put("date", dateFormat.format(date));
        map.put("time", timeFormat.format(date));
        return map;
    }

    public static String getWeek(String dateString) {
        Calendar c = Calendar.getInstance();
        Date date = null;
        try {
            date = new SimpleDateFormat("yy-MM-dd").parse(dateString);
            c.setTime(date);
            return String.valueOf(Math.max(c.get(Calendar.DAY_OF_WEEK) - 1, 0));
        } catch (ParseException e) {
            logger.error(e.getMessage(), e);
        }
        return "-1";
    }

    public static String getNumberWeek(Date date) {
        String[] weeks = {"0", "1", "2", "3", "4", "5", "6"};
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        int week_index = cal.get(Calendar.DAY_OF_WEEK) - 1;
        if (week_index < 0) {
            week_index = 0;
        }
        return weeks[week_index];
    }

    public static int getMonthDay(int year, int month) {
        int[] days = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
            days[1] = 29;
        }
        String lastDay = "00".substring(0, 2 - String.valueOf(days[month - 1]).length()) + days[month - 1];
        return Integer.parseInt(lastDay);
    }

    public static int getMonthDay(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        return cal.getActualMaximum(Calendar.DATE);
    }


    public static String addDateStr(Date d, int days, String sdf) {
        Calendar c = Calendar.getInstance();
        c.setTime(d);
        c.add(Calendar.DAY_OF_YEAR, days);
        DateFormat df = new SimpleDateFormat(sdf);
        return df.format(c.getTime());
    }


    /***
     * 获取出生天数
     * @param dateString
     * @return
     */
    public static int getBirthDays(String dateString) {
        Calendar now = Calendar.getInstance();
        Calendar post = Calendar.getInstance();
        Date date = null;
        try {
            date = new SimpleDateFormat("yy-MM-dd").parse(dateString);
        } catch (ParseException e) {
            logger.error(e.getMessage(), e);
        }
        post.setTime(date);
        return (int) ((now.getTimeInMillis() - post.getTimeInMillis()) / 86400000L);
    }


    /**
     * @param start 开始日期
     * @param end   结束日期
     * @return 天数
     * @description 获取两个日期相差的天数
     * @author ryan.li
     * @date 2022/10/24 10:05
     */
    public static int getIntervalDays(String start, String end) {
        Calendar sc = Calendar.getInstance();
        Calendar ec = Calendar.getInstance();
        Date sdate = null;
        Date edate = null;
        try {
            sdate = new SimpleDateFormat("yy-MM-dd").parse(start);
            edate = new SimpleDateFormat("yy-MM-dd").parse(end);
        } catch (ParseException e) {
            logger.error(e.getMessage(), e);
        }
        sc.setTime(sdate);
        ec.setTime(edate);
        return Math.abs((int) ((ec.getTimeInMillis() - sc.getTimeInMillis()) / 86400000L));
    }

    public static int getIntervalHours(String start, String end) {
        Calendar sc = Calendar.getInstance();
        Calendar ec = Calendar.getInstance();
        Date sdate = null;
        Date edate = null;
        try {
            sdate = new SimpleDateFormat(FORMAT_DATETIME_MM).parse(start);
            edate = new SimpleDateFormat(FORMAT_DATETIME_MM).parse(end);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        sc.setTime(sdate);
        ec.setTime(edate);
        return Math.abs((int) ((ec.getTimeInMillis() - sc.getTimeInMillis()) / 3600000L));
    }

    /**
     * @param start
     * @param end
     * @return 两个时间的时间差 分钟
     * 如果时间异常 则返回  Integer.MAX_VALUE
     * @description 两个时间的时间差 分钟
     * @author ryan.li
     * @date 2022/10/21 14:32
     */
    public static int getIntervalMinus(String start, String end) {
        Calendar sc = Calendar.getInstance();
        Calendar ec = Calendar.getInstance();
        try {
            Date sdate = new SimpleDateFormat(FORMAT_DATETIME_MM).parse(start);
            Date edate = new SimpleDateFormat(FORMAT_DATETIME_MM).parse(end);
            sc.setTime(sdate);
            ec.setTime(edate);
            return Math.abs(Long.valueOf((ec.getTimeInMillis() - sc.getTimeInMillis()) / 60000L).intValue());
        } catch (ParseException e) {

        }
        return Integer.MAX_VALUE;
    }

    public static int getIntervalMinus(Date start, Date end) {
        Calendar sc = Calendar.getInstance();
        Calendar ec = Calendar.getInstance();
        sc.setTime(start);
        ec.setTime(end);
        return Math.abs(Long.valueOf((ec.getTimeInMillis() - sc.getTimeInMillis()) / 60000L).intValue());
    }

    public static int getMinute(Date date1, Date date2) {
        int minute = 0;
        minute = (int) Math.abs((date1.getTime() - date2.getTime()) / 60000L);
        return minute;
    }


    public static String formatCurrentTime(String patten) {
        return format(new Date(), patten);
    }


    /**
     * @param year_
     * @param month_
     * @param day_
     * @return
     * @description 获取农历
     * @author ryan.li
     * @date 2022/10/24 10:15
     */
    public static String getLunarDate(int year_, int month_, int day_) {
        Calendar now = Calendar.getInstance();
        now.set(year_, month_, day_);
        int week_num = now.get(Calendar.DAY_OF_WEEK);
        if (week_num == 1 || week_num == 7) {
            return format(now.getTime(), FORMAT_DATE);
        }
        return null;
    }


    public static List<String> findDaysStr(String beginTime, String endTime) {
        SimpleDateFormat sdf = new SimpleDateFormat(FORMAT_DATE);
        Date dBegin = null;
        Date dEnd = null;
        try {
            dBegin = sdf.parse(beginTime);
            dEnd = sdf.parse(endTime);
        } catch (ParseException e) {

        }
        List<String> daysStrList = new ArrayList<String>();
        daysStrList.add(sdf.format(dBegin));
        Calendar calBegin = Calendar.getInstance();
        calBegin.setTime(dBegin);
        Calendar calEnd = Calendar.getInstance();
        calEnd.setTime(dEnd);
        while (dEnd.after(calBegin.getTime())) {
            calBegin.add(Calendar.DATE, 1);
            String dayStr = sdf.format(calBegin.getTime());
            daysStrList.add(dayStr);
        }
        return daysStrList;
    }

    /**
     * 获取两个日期中间的月份列表
     * yyyy-MM
     *
     * @param beginTime
     * @param endTime
     * @return
     * @throws ParseException
     */
    public static List<String> findMonthsStr(String beginTime, String endTime) throws ParseException {
        List<String> monthsStrList = new ArrayList<String>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        Calendar min = Calendar.getInstance();
        Calendar max = Calendar.getInstance();
        min.setTime(sdf.parse(beginTime));
        min.set(min.get(Calendar.YEAR), min.get(Calendar.MONTH), 1);
        max.setTime(sdf.parse(endTime));
        max.set(max.get(Calendar.YEAR), max.get(Calendar.MONTH), 2);
        while (min.before(max)) {
            monthsStrList.add(sdf.format(min.getTime()));
            min.add(Calendar.MONTH, 1);
        }
        return monthsStrList;
    }

    public static List<String> findYearsStr(String beginTime, String endTime) {
        List<String> yearsStrList = new ArrayList<String>();
        beginTime = beginTime.substring(0, 4);
        endTime = endTime.substring(0, 4);
        if (beginTime.equals(endTime)) {
            yearsStrList.add(beginTime);
        } else {
            yearsStrList.add(beginTime);
            for (int i = 1; i <= Integer.parseInt(endTime) - Integer.parseInt(beginTime); ++i) {
                yearsStrList.add(String.valueOf(Integer.parseInt(beginTime) + i));
            }
        }
        return yearsStrList;
    }


    public static List<String> getIntervalDate(String date, int day) {
        String beginDate = date2Str(dateAdd(date, -day), FORMAT_DATE);
        String endDate = date2Str(dateAdd(date, day), FORMAT_DATE);
        List<String> intervalList = findDaysStr(beginDate, endDate);
        return intervalList;
    }


    public static boolean isEffectiveDate(String startDate, String endDate, String dateFormat) {
        Date startTime = parse(startDate, dateFormat);
        Date endTime = parse(endDate, dateFormat);
        Date nowTime = new Date();
        if (nowTime.getTime() == startTime.getTime() || nowTime.getTime() == endTime.getTime()) {
            return true;
        }
        Calendar date = Calendar.getInstance();
        date.setTime(nowTime);
        Calendar begin = Calendar.getInstance();
        begin.setTime(startTime);
        Calendar end = Calendar.getInstance();
        end.setTime(endTime);
        if (date.after(begin) && date.before(end)) {
            return true;
        }
        return false;
    }

    public static Date parseDateV2(String dateStr, String type) {
        if (StringUtils.isBlank(dateStr)) {
            return null;
        }
        SimpleDateFormat dateFormat = new SimpleDateFormat(type);
        try {
            return dateFormat.parse(dateStr);
        } catch (ParseException e) {
            return null;
        }
    }


    /**
     * 年龄描述转出生天数
     *
     * @param age
     * @return
     */
    public static int util2Day(String age) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        int ageNum = 0;
        if (age.contains("岁")) {
            ageNum = Integer.parseInt(age.substring(0, age.indexOf("岁")));
            calendar.add(Calendar.YEAR, -ageNum);
            if (age.contains("月")) {
                ageNum = Integer.parseInt(age.substring(age.indexOf("岁") + 1, age.indexOf("月")));
                calendar.add(Calendar.MONTH, -ageNum);
                if (age.contains("周")) {
                    ageNum = Integer.parseInt(age.substring(age.indexOf("月") + 1, age.indexOf("周")));
                    calendar.add(Calendar.WEEK_OF_YEAR, -ageNum);
                    if (age.contains("天")) {
                        ageNum = Integer.parseInt(age.substring(age.indexOf("周") + 1, age.indexOf("天")));
                        calendar.add(Calendar.DATE, -ageNum);
                    }
                } else if (age.contains("天")) {
                    ageNum = Integer.parseInt(age.substring(age.indexOf("月") + 1, age.indexOf("天")));
                    calendar.add(Calendar.DATE, -ageNum);
                }
            } else if (age.contains("周")) {
                ageNum = Integer.parseInt(age.substring(age.indexOf("岁") + 1, age.indexOf("周")));
                calendar.add(Calendar.WEEK_OF_YEAR, -ageNum);
                if (age.contains("天")) {
                    ageNum = Integer.parseInt(age.substring(age.indexOf("周") + 1, age.indexOf("天")));
                    calendar.add(Calendar.DATE, -ageNum);
                }
            } else if (age.contains("天")) {
                ageNum = Integer.parseInt(age.substring(age.indexOf("岁") + 1, age.indexOf("天")));
                calendar.add(Calendar.DATE, -ageNum);
            }
        } else if (age.contains("月")) {
            ageNum = Integer.parseInt(age.substring(0, age.indexOf("月")));
            calendar.add(Calendar.MONTH, -ageNum);
            if (age.contains("周")) {
                ageNum = Integer.parseInt(age.substring(age.indexOf("月") + 1, age.indexOf("周")));
                calendar.add(Calendar.WEEK_OF_YEAR, -ageNum);
                if (age.contains("天")) {
                    ageNum = Integer.parseInt(age.substring(age.indexOf("周") + 1, age.indexOf("天")));
                    calendar.add(Calendar.DATE, -ageNum);
                }
            } else if (age.contains("天")) {
                ageNum = Integer.parseInt(age.substring(age.indexOf("月") + 1, age.indexOf("天")));
                calendar.add(Calendar.DATE, -ageNum);
            }
        } else if (age.contains("周")) {
            ageNum = Integer.parseInt(age.substring(0, age.indexOf("周")));
            calendar.add(Calendar.WEEK_OF_YEAR, -ageNum);
            if (age.contains("天")) {
                ageNum = Integer.parseInt(age.substring(age.indexOf("周") + 1, age.indexOf("天")));
                calendar.add(Calendar.DATE, -ageNum);
            }
        } else if (age.contains("天")) {
            ageNum = Integer.parseInt(age.substring(0, age.indexOf("天")));
            calendar.add(Calendar.DATE, -ageNum);
        }
        String dateStr = new SimpleDateFormat(FORMAT_DATE).format(calendar.getTime());
        return StringUtils.isNotBlank(dateStr) ? getBirthDays(dateStr) : 0;
    }


    public static String day2Age(int day) {
        //String dateStr = date2Str(,FORMAT_DATE) ;
        return String.valueOf(getAge(dateAdd(new Date(), -day)));
    }

    public static int daysOfTwo(Date date1, Date date2) {
        Calendar aCalendar = Calendar.getInstance();
        aCalendar.setTime(date1);
        int day1 = aCalendar.get(Calendar.DAY_OF_YEAR);
        aCalendar.setTime(date2);
        int day2 = aCalendar.get(Calendar.DAY_OF_YEAR);
        return day2 - day1;
    }


    public static Date getDayBefore(Date date, Integer day) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.DATE, -day);
        return calendar.getTime();
    }

    public static String msecToTime(long time) {
        String timeStr = null;
        long hour = 0L;
        long minute = 0L;
        long second = 0L;
        if (time <= 0L) {
            return "00:00:00";
        }
        second = time / 1000L;
        minute = second / 60L;
        if (second < 60L) {
            timeStr = "00:00:" + unitFormat(second);
        } else if (minute < 60L) {
            second %= 60L;
            timeStr = "00:" + unitFormat(minute) + ":" + unitFormat(second);
        } else {
            hour = minute / 60L;
            minute %= 60L;
            second = second - hour * 3600L - minute * 60L;
            timeStr = unitFormat(hour) + ":" + unitFormat(minute) + ":" + unitFormat(second);
        }
        return timeStr;
    }

    public static String unitFormat(long i) {
        String retStr = null;
        if (i >= 0L && i < 10L) {
            retStr = "0" + i;
        } else {
            retStr = "" + i;
        }
        return retStr;
    }

    public static boolean isToday(String dateString) {
        String today = new SimpleDateFormat(FORMAT_DATE).format(new Date());
        return today.compareTo(dateString) == 0;
    }

    public static boolean checkCurrentTimeIsCycle(String cycle, Date date) {
        List<String> stringList = CommonUtil.strToList(cycle, "~");
        if (stringList != null && stringList.size() > 0) {
            String dateStart = stringList.get(0);
            String dateEnd = stringList.get(1);
            List<Date> cycleDate = null;
            try {
                if (dateStart.length() < 6) {
                    Calendar cale = Calendar.getInstance();
                    cale.setTime(date);
                    int i = cale.get(2) + 1;
                    String currentYear = String.valueOf(cale.get(1));
                    dateStart = currentYear + "-" + dateStart;
                    dateEnd = currentYear + "-" + dateEnd;
                    Integer dateStartMarch = Integer.valueOf(dateStart.substring(5, 7));
                    Integer dateEndMarch = Integer.valueOf(dateEnd.substring(5, 7));
                    boolean newYear = isNewYear(dateStart, dateEnd);
                    if (newYear) {
                        dateEnd = Integer.parseInt(currentYear) + 1 + "-" + stringList.get(1);
                    } else {
                        dateEnd = currentYear + "-" + stringList.get(1);
                    }
                    if (newYear && dateStartMarch == i) {
                        dateEnd = String.valueOf(Integer.parseInt(currentYear) + 1) + "-" + stringList.get(1);
                        dateStart = currentYear + "-" + stringList.get(0);
                    }
                    if (newYear && dateEndMarch == i) {
                        dateStart = String.valueOf(Integer.parseInt(currentYear) - 1) + "-" + stringList.get(0);
                        dateEnd = currentYear + "-" + stringList.get(1);
                    }
                }
                cycleDate = getCycleDate(dateStart, dateEnd);
            } catch (ParseException e) {
                e.printStackTrace();
            }
            boolean activityTime = isActivityTime(date, cycleDate.get(0), cycleDate.get(1));
            return activityTime;
        }
        return false;
    }

    public static List<Date> getCycleDate(String dateStart, String dateEnd) throws ParseException {
        ArrayList<Date> arrayList = new ArrayList<Date>();
        Date start = parse(dateStart, FORMAT_DATE);
        Date end = parse(dateEnd, FORMAT_DATE);
        arrayList.add(start);
        arrayList.add(end);
        return arrayList;
    }

    public static boolean isActivityTime(Date nowDate, Date startDate, Date endDate) {
        if (!isSameDate(startDate, nowDate) && !isSameDate(endDate, nowDate)) {
            long today = nowDate.getTime();
            long startTime = startDate.getTime();
            long endTime = endDate.getTime();
            if (today < startTime || today > endTime) {
                return false;
            }
        }
        return true;
    }

    public static boolean isNewYear(String dateStart, String dateEnd) throws ParseException {
        SimpleDateFormat df = new SimpleDateFormat("MM-dd");
        Date dt1 = df.parse(dateStart);
        Date dt2 = df.parse(dateEnd);
        return dt1.after(dt2);
    }


    public static String addOrSubtractTime(String time, Long data, boolean check) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(FORMAT_DATETIME);
        LocalDateTime now = LocalDateTime.now();
        int year = now.getYear();
        int monthValue = now.getMonthValue();
        int dayOfMonth = now.getDayOfMonth();
        String month = "";
        String day = "";
        if (monthValue < 10) {
            month = "0" + monthValue;
        } else {
            month = "" + monthValue;
        }
        if (dayOfMonth < 10) {
            day = "0" + dayOfMonth;
        } else {
            day = "" + dayOfMonth;
        }
        LocalDateTime parse = LocalDateTime.parse(year + "-" + month + "-" + day + " " + time, formatter);
        LocalDateTime localDateTime = null;
        if (check) {
            localDateTime = parse.minusSeconds(data);
        } else {
            localDateTime = parse.plusSeconds(data);
        }
        DateTimeFormatter formatt = DateTimeFormatter.ofPattern(FORMAT_TIME);
        return localDateTime.format(formatt);
    }

    /**
     * 按照指定小时分割时间段
     *
     * @param dateType 类型 M/D/H/N -->每月/每天/每小时/每分钟
     * @param dBegin   开始时间
     * @param dEnd     结束时间
     *                 * @param time 指定小时(如：1、2、3、4)
     * @return
     */
    public static List<String> findDates(String dateType, Date dBegin, Date dEnd, int time) throws Exception {
        List<String> listDate = new ArrayList<>();
        listDate.add(new SimpleDateFormat("HH:mm").format(dBegin));
        Calendar calBegin = Calendar.getInstance();
        calBegin.setTime(dBegin);
        Calendar calEnd = Calendar.getInstance();
        calEnd.setTime(dEnd);
        while (calEnd.after(calBegin)) {
            if ("H".equals(dateType)) {
                calBegin.add(Calendar.HOUR, time);
            }
            if ("M".equals(dateType)) {
                calBegin.add(Calendar.MONTH, time);
            }
            if ("D".equals(dateType)) {
                calBegin.add(Calendar.DATE, time);
            }
            if ("N".equals(dateType)) {
                calBegin.add(Calendar.MINUTE, time);
            }
            if (calEnd.after(calBegin)) {
                listDate.add(new SimpleDateFormat("HH:mm").format(calBegin.getTime()));
            } else {
                listDate.add(new SimpleDateFormat("HH:mm").format(calEnd.getTime()));
            }

        }
        return listDate;
    }


    public static void main(String[] args) {
        System.out.println(getCurrentYear());
    }
}
